package cn.tedu.csmall520.commons.restful;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data

public class JsonPage<T> implements Serializable {
//  当前类在实际开发中替代Page/PageInfo

    @ApiModelProperty(value = "总页数",name = "totalPages")
    private Integer totalPages;

    @ApiModelProperty(value = "总条数",name = "totalCount")
    private Long totalCount;

    @ApiModelProperty(value = "页码",name = "page")
    private Integer page;

    @ApiModelProperty(value = "每页条数",name = "pageSize")
    private Integer pageSize;

//    JsonPage对象要能够保存分页数据
    @ApiModelProperty(value = "分页数据",name = "list")
    private List<T> list;

//    下面编写一个方法，能够实现将PageInfo类型对象转换为JsonPage对象返回
    public static <T> JsonPage<T> restPage(PageInfo<T> pageInfo){
        // 将参数pageInfo对象相同意义的属性赋值到JsonPage
        JsonPage<T> jsonPage = new JsonPage<>();
        jsonPage.setTotalPages(pageInfo.getPages());
        jsonPage.setTotalCount(pageInfo.getTotal());
        jsonPage.setPage(pageInfo.getPageSize());
        jsonPage.setList(pageInfo.getList());
        return jsonPage;
    }


}
